|
|
|
|
|
|
|
Retrieving Data Using API Calls |
|
|
|
|
|
|
|
|
In the Click event of the cmdGet command button, youll see a lot of code. Using the Windows API calls to manipulate the Registry is not a lot of fun because it takes a lot of work. Dont worry, though, because youll learn to use the built-in Visual Basic functions to simplify this code quite a bit. You need to know how to use these API calls, however, because you might need to access another area of the Registry at some point. Heres the code: |
|
|
|
 |
|
|
|
|
Private Sub cmdReg_Click()
Dim lngStatus As Long
Dim lngKey As Long
Dim strKey As String
Dim bytBuf(MAX_BYTES) As Byte
Dim lngType As Long
Dim vntValue As Variant
' This is the key you wish to retrieve strKey = "Software" & _
"\VB and VBA Program Settings" & _
"\" & txtConfig & _
"\" & txtSection
' Attempt to open the registry key. lngStatus = RegOpenKeyEx(ByVal HKEY_CURRENT_USER, _
ByVal strKey, _
ByVal 0, _
ByVal KEY_READ, _
lngKey)
If lngStatus = ERROR_SUCCESS Then strKey = txtKeyName ' Now try to read the value lngStatus = RegQueryValueEx(ByVal lngKey, _
ByVal strKey, _
ByVal 0, _
lngType, _
bytBuf(0), _
MAX_BYTES) |
|
|
|
|
|